<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Gentelella Alela! | </title>

    <!-- Bootstrap -->
    <link href="/resources/gentelella/vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="/resources/gentelella/vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="/resources/gentelella/vendors/nprogress/nprogress.css" rel="stylesheet">
    <!-- iCheck -->
    <link href="/resources/gentelella/vendors/iCheck/skins/flat/green.css" rel="stylesheet">

    <!-- bootstrap-progressbar -->
    <link href="/resources/gentelella/vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css" rel="stylesheet">
    <!-- JQVMap -->
    <link href="/resources/gentelella/vendors/jqvmap/dist/jqvmap.min.css" rel="stylesheet"/>
    <!-- bootstrap-daterangepicker -->
    <link href="/resources/gentelella/vendors/bootstrap-daterangepicker/daterangepicker.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="/resources/gentelella/css/custom.min.css" rel="stylesheet">
    <link rel="stylesheet" href="/resources/datatables/dataTables.bootstrap.css?v=2">
    <link href="/resources/gentelella/vendors/datatables.net-bs/css/dataTables.bootstrap.min.css" rel="stylesheet">
    <link href="/resources/paginator/css/bootstrap-combined.min.css" rel="stylesheet">
    <link href="/resources/css/self.css" rel="stylesheet">
    <!-- table -->
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/datatables/jquery.dataTables.min.js"></script>
    <script src="/resources/datatables/dataTables.bootstrap.min.js"></script>
    <script src="/resources/paginator/js/bootstrap-paginator.js"></script>
    <script src="/resources/js/self.js"></script>
    <style type="text/css">
        .form-data{
            width: 150px !important;
        }
    </style>
</head>

<body style="background-color: #fff !important;">
<div class="col-md-12">
    <div class="box-body" style="padding-bottom:10px;">
        <div class="row form-inline" style="margin-left: 20px;">

          <!--  <div class="form-group">
                <input type="hidden" class="form-control form-data" name="process"/>
                <input type="hidden" class="form-control form-data" name="refuseFlag"/>
                <label>名称:</label>
                <input type="text" class="form-control form-data" name="name"/>
            </div>-->
            <div class="form-group">
                <label>销售企业:</label>
                <select name="companyId" id="companyId" class="form-control form-data">
                    <option value="">全部</option>
                </select>

            </div>

            <div class="form-group">
                <label>产品:</label>
                <select name="productId" id="productId" class="form-control form-data">
                    <option value="">全部</option>
                </select>

            </div>

            <div class="form-group">
                <label>购买企业:</label>
                <select name="buyCompanyId" id="buyCompanyId" class="form-control form-data">
                    <option value="">全部</option>
                </select>

            </div>
            <div class="form-group">
                <label>运输公司</label>
                <select name="transportCompanyId" id="transportCompanyId" class="form-control form-data">
                    <option value="">全部</option>
                </select>
            </div>
        </div>
        <div class="row form-inline" style="margin-left: 20px;margin-top: 15px;">


            <div class="form-group">
                <input type="hidden" class="form-control form-data" name="process"/>
                <label>时间</label>
                <input type="text" id="timeB" name="timeB" class="form-control form-data"
                       onclick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
            </div>
            <div class="form-group">
                <input type="hidden" class="form-control form-data" name="process"/>
                <label>-</label>
                <input type="text" id="timeE" name="timeE" class="form-control form-data"
                       onclick="WdatePicker({dateFmt:'yyyy-MM-dd  HH:mm:ss'})">
            </div>
            <button type="button"  onclick="searchData()" class="btn btn-primary">查询</button>

        </div>

    </div>
    <div class="x_panel">

        <table id="example" class="table table-bordered table-striped dataTable" cellspacing="0" width="100%">
            <thead>
            <tr>
                <th>选择</th>
                <th class="serial">序号</th>
                <th>销售企业</th>
                <!--<th>名称</th>-->
                <th>购买方</th>
                <th>产品</th>
                <th>销售量</th>
                <th>采集数值</th>
                <th>对冲数值</th>
                <th>采购量</th>
                <th>单位</th>
                <th>销售时间</th>
            </tr>
            </thead>
        </table>
        <div id="example_page">
        </div>
    </div>
</div>


</body>
<script type="text/javascript">
    //列名称
    var columns = ["id","id","company","buyCompany",/*"transportCompany",*/"productName"," amount","monitorValueLora",
        "offsetOrder","buyAmount","unit","createTime"];
    var createdCellFun = function (td, cellData, rowData, row, col) {
        /* $(td).css('color', 'red');*/
        switch (col){
            case 0:
                var html = "";
                if(rowData.pullFlag =='n'){

                }

                html += "<input type='checkbox' value='"+cellData+"' name='select' pullData='"+rowData.pullFlag+"'/>";

                $(td).html(html);
                break;
            case 1:
                $(td).html( (row+1));
                break;
            case 2:
                var html ="";
                if(!isNullOrUndefined(rowData.company)){
                    html += "<a href='javascript:void(0);' onclick='showWithId(\""+rowData.id+"\")' >"+rowData.company.name+"</a>";

                    $(td).html(html);
                }else {
                    html += "<a href='javascript:void(0);' onclick='showWithId(\""+rowData.id+"\")' >未配置公司</a>";
                    $(td).html("html");
                }
                break;
            case 3:

                if(!isNullOrUndefined(rowData.buyCompany)){
                    var html = "";
                    html += "<a href='javascript:void(0);' onclick='showBuyCompany(\""+rowData.buyCompany.id+"\")' >"+rowData.buyCompany.name+"</a>";
                    $(td).html(html);
                    break;
                }else {
                    $(td).html("");
                }
                break;
           /* case 2:

                if(rowData.transportCompany != null){
                    var html = "";
                    html += rowData.transportCompany.name;
                    $(td).html(html);
                    break;
                }else {
                    $(td).html("");
                }
                break;*/
            case 5:
                $(td).html(rowData.amount);
                break;
            case 6:
                if(!isNullOrUndefined(rowData.monitorValueLora)){
                    $(td).html(rowData.monitorValueLora.calcValue);
                }else {
                    $(td).html("0");
                }

                break;
            case 7:
                if(!isNullOrUndefined(rowData.offsetOrder)){
                    $(td).html(rowData.offsetOrder.value);
                }else {
                    $(td).html("0");
                }

                break;
            case 10:
                $(td).html(new Date(cellData).format("yyyy-MM-dd"));
                break;

        }
    }
    $(function () {

        var  companyId =  getUrlParam("companyId");
        var  timeBegin =  getUrlParam("timeBegin");
        var  timeEnd =  getUrlParam("timeEnd");
        var  productId =  getUrlParam("productId");

        buildSelect("/admin/company/listAll.do","#companyId","id","name",{});
        buildSelect("/admin/mProduct/listAll.do","#productId","id","name",{});
        buildSelect("/admin/buyCompany/listAllForSelect.do","#buyCompanyId","id","name",{});
        buildSelect("/admin/transportCompany/listAll.do","#transportCompanyId","id","name",{});
        $("#companyId").val(companyId);
        $("#timeB").val(timeBegin);
        $("#timeE").val(timeEnd);
        $("#productId").val(productId);
        $("#companyId").attr("readonly","readonly");
        $("#timeB").attr("readonly","readonly");
        $("#timeE").attr("readonly","readonly");
        $("#productId").attr("readonly","readonly");


        buildPage("#example");
        var param = getParam();
        initDataTable("#example", "/admin/saleOrder/list.do",param,columns,createdCellFun);
    });
    function getParam(){
        var param = getPageDataByClass("form-data");
        if(isNullOrUndefined(param['timeB'])){
            param['timeB'] = 0;
        }else {
            param['timeB'] = new Date(param['timeB'] ).getTime();
        }
        if(isNullOrUndefined(param['timeE'])){
            param['timeE'] = 0;
        }else {
            param['timeE'] = new Date(param['timeE'] ).getTime();
        }
        param['page']= 1;
        param['size']= 10;
        return param;
    }
    function buildPage(element) {
        var param = getParam();
        //点击分页页面按钮
        var clickFun = function (e, originalEvent, type, page) {
            //构建查询参数
            param = getParam();
            param['size'] = 10;
            _page = page;
            param['page'] = page;
            initDataTable("#example", "/admin/saleOrder/list.do", param, columns, createdCellFun);
        }
        $.ajax({
            url:"/admin/saleOrder/count.do?_t=" + new Date().getTime(),
            data: param ,
            type:'post',
            dataType:"json",  //xml  html   script  jsonp
            success:function(result){
                initPage($("#example_page"),1,result.data,clickFun);
            }
        });
    }
    function searchData() {
        var param = getParam();
        initDataTable("#example", "/admin/saleOrder/list.do", param, columns, createdCellFun);
        buildPage("#example");
    }

    function show() {
        var data = getData();
        var id = getOneSelectChecked();
        if(isNullOrUndefined(id)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        goto("process.html",{"id":id,"process":data.process});
    }
    function showWithId(id) {
        var data = getData();
        goto("process.html",{"id":id,"process":data.process});
    }
    function pullData() {
        var id = getOneSelectChecked();
        if(isNullOrUndefined(id)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        var pullData = $("input[value='"+id+"']").attr('pullData');
        if(pullData != 'n') {
            alert("不能同步数据");
            return;
        }
        $.ajax({
            url: "/admin/saleOrder/pullData.do",
            data: {"id":id},
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("操作成功");
                } else {
                    alert(data.msg);
                }
            }
        });
    }
    function remark() {
        var data = getData();
        var id = getOneSelectChecked();
        if(isNullOrUndefined(id)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        goto("sale_order_remark.html",{"id":id,"process":data.process,"refuseFlag":data.refuseFlag});
    }
    function showBuyCompany() {
        var data = getData();
        var id = getOneSelectChecked();
        if(isNullOrUndefined(id)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        goto("buyCompany_show.html",{"id":id,"process":data.process,"refuseFlag":data.refuseFlag,"back_url":"sale_order_list.html"});
    }

    function offsetOrder() {
        var data = getData();
        var saleOrderId = getOneSelectChecked();
        if(isNullOrUndefined(saleOrderId)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        goto("offset_order.html",{"saleOrderId":saleOrderId,"process":data.process,"refuseFlag":data.refuseFlag,"back_url":"sale_order_list.html"});
    }


    //通用 获取列表中选择的数据的id
    function getSelectChecked() {
        var ids = [];
        $("input[name='select']:checked").each(function(){
            ids.push($(this).prop("value"));
        });
        return ids;
    }
    function getOneSelectChecked() {
        var ids = getSelectChecked();
        if(ids.length == 0 || ids.length > 1) {
            return null;
        }
        return ids[0];
    }
    function checkAllSelect(node) {
        if($(node).prop("checked")) {
            $("input[name='select']").each(function(){
                $(this).prop("checked", true);
            });
        } else {
            $("input[name='select']").each(function(){
                $(this).prop("checked", false);
            });
        }
    }
</script>
</html>